#include "wtlpch.h"

#include "resource.h"
#include "AppConfigDiag.h"

#define OPTION_CAT_NUM		5
#define MAX_OPTION_TEXT		32

CAppConfigDiag::CAppConfigDiag(void)
{
}

CAppConfigDiag::~CAppConfigDiag(void)
{
}

LRESULT CAppConfigDiag::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	CenterWindow(GetParent());

	//Create the Image List
	m_imglstTree.Create(16, 16, ILC_COLOR32, OPTION_CAT_NUM, 0);
	m_imglstTree.AddIcon(::LoadIconW(::GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_OPT_JS)));
	m_imglstTree.AddIcon(::LoadIconW(::GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_OPT_TIMEOUT)));

	//Attach with the tree view And set image list
	m_treeOptions.Attach(GetDlgItem(IDC_OPTION_TREE));
	m_treeOptions.SetImageList(m_imglstTree, TVSIL_NORMAL);

	//Add Options to Tree
	AddOptionsToTree();


	return TRUE;
}

LRESULT CAppConfigDiag::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	return TRUE;
}

LRESULT CAppConfigDiag::OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	
	EndDialog(1);

	return TRUE;
}

LRESULT CAppConfigDiag::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	return TRUE;
}

void CAppConfigDiag::AddOptionsToTree()
{
	//Buffer for Option text
	WCHAR* lpwstrOptText = new WCHAR[MAX_OPTION_TEXT];

	//Set App Options
	::wmemset(lpwstrOptText, 0, MAX_OPTION_TEXT);
	::LoadStringW(::GetModuleHandle(NULL), IDS_TA_OPTION_APPSETTING, lpwstrOptText, MAX_OPTION_TEXT);

	CTreeItem tiAppItem = m_treeOptions.InsertItem(lpwstrOptText, TVI_ROOT, TVI_LAST);
	tiAppItem.SetImage(0, 0);

	//Set JSOptions
	::wmemset(lpwstrOptText, 0, MAX_OPTION_TEXT);
	::LoadStringW(::GetModuleHandle(NULL), IDS_TA_OPTION_JSSETTING, lpwstrOptText, MAX_OPTION_TEXT);

	CTreeItem tiJSItem = m_treeOptions.InsertItem(lpwstrOptText, TVI_ROOT, TVI_LAST);
	tiJSItem.SetImage(0, 0);

	CTreeItem tiJSSubTimeOut = tiJSItem.AddTail(L"SubSet", 2);

	delete lpwstrOptText;
}
